package com.shop2cn.iapi.wxcomponent.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.wxcomponent.parameter.AppStatusEnum;
import com.shop2cn.iapi.wxcomponent.parameter.ChargeStatusEnum;
import com.shop2cn.iapi.wxcomponent.parameter.GetMchAppAllStatusBean;
import com.shop2cn.iapi.wxcomponent.parameter.PayChannelStatusEnum;
import com.shop2cn.iapi.wxcomponent.service.GetMchAppAllStatusCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.Mchapp;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
/**
*查询小程序所有状态
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetMchAppAllStatus{
	private static GetMchAppAllStatusBean getmchappallstatusBean;
	private static GetMchAppAllStatusCall getmchappallstatusCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询小程序所有状态");
	}

	@Before
	public void caseUp() {
		getmchappallstatusBean=new GetMchAppAllStatusBean();
		getmchappallstatusCall=new GetMchAppAllStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getmchappallstatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMchAppAllStatus_001() {
		Logger.start(true,"查询小程序所有状态");
		try {
			DefGodMchWapper DefGodMchWapper=new DefGodMchWapper();
			Mchapp defmchapp = DefGodMchWapper.selectMchappByExample(null).get(0);
			System.out.println(defmchapp);
			getmchappallstatusBean.setMchId(defmchapp.getMchId());
			getmchappallstatusCall.setData(getmchappallstatusBean);
			getmchappallstatusCall.callService();			
			Logger.verifyEquals("200", getmchappallstatusCall.getString("code"), "验证返回code");
			JsonObject ja = getmchappallstatusCall.getJsonObject().get("data").getAsJsonObject();
			Logger.verifyEquals(ja.get("appId").getAsString(),defmchapp.getAppId(), "验证返回appId");
			Logger.verifyEquals(ja.get("appStatus").getAsInt(),defmchapp.getAppStatus(), "验证返回appStatus");
			//TODO ？appStatusValue
			Logger.verifyEquals(ja.get("appStatusValue").getAsString(),AppStatusEnum.getByCode( defmchapp.getAppStatus()).getMessage(), "验证返回appStatusValue");
			Logger.verifyEquals(ja.get("isPublished").getAsBoolean(),defmchapp.getIsPublished(), "验证返回isPublished");
			Logger.verifyEquals(ja.get("payChannelStatus").getAsInt(),defmchapp.getPayChannelStatus(), "验证返回payChannelStatus");
			//TODO ？payChannelStatusValue
			Logger.verifyEquals(ja.get("payChannelStatusValue").getAsString(),PayChannelStatusEnum.getByCode( defmchapp.getPayChannelStatus()).getMessage(), "验证返回payChannelStatusValue");
			Logger.verifyEquals(ja.get("chargeStatus").getAsInt(),defmchapp.getChargeStatus(), "验证返回chargeStatus");
//			Logger.verifyEquals(ja.get("chargeStatusValue").getAsString(),ChargeStatusEnum.getByCode( defmchapp.getChargeStatus()).getMessage(), "验证返回chargeStatusValue");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMchAppAllStatus_002() {
		Logger.start(true,"不输入MchId失败");
		try {
//			getmchappallstatusBean.setMchId("12321");
			getmchappallstatusCall.setData(getmchappallstatusBean);
			getmchappallstatusCall.callService();			
			Logger.verifyEquals("400", getmchappallstatusCall.getString("code"), "验证返回code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMchAppAllStatus_003() {
		Logger.start(true,"输入错误MchId失败");
		try {
			getmchappallstatusBean.setMchId(-1);
			getmchappallstatusCall.setData(getmchappallstatusBean);
			getmchappallstatusCall.callService();			
			Logger.verifyEquals("200", getmchappallstatusCall.getString("code"), "验证返回code");
			Logger.verifyEquals(true,getmchappallstatusCall.getJsonObject().get("data").isJsonNull(), "验证无此数据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}